import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';
import 'package:interrogation/assets/const.dart';
import 'package:interrogation/src/module/chat/chat_page/views/chat_page_view.dart';
import 'package:interrogation/src/module/home/homePage/views/home_page_view.dart';
import 'package:interrogation/src/module/mine/mine_page/views/mine_page_view.dart';

import '../../../mine/doctor_mine_page/views/doctor_mine_page_view.dart';
import '../controllers/home_index_controller.dart';

class HomeIndexView extends GetView<HomeIndexController> {
  const HomeIndexView({super.key});

  int get currentIndex => controller.currentIndex.value;

  PageController get pageController => controller.pageController;

  Duration get _duration =>Duration(milliseconds: 450);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[100],
      extendBody: true,
      body: PageView(
        controller: pageController,
        onPageChanged: (int value) {
          controller.onPageChange(value);
        },
        children: [
          HomePageView(),
          ChatPageView(),
          controller.isDoctor
              ? DoctorMinePageView()
              : MinePageView()
        ],
      ),
      bottomNavigationBar: SafeArea(
        child: Obx(() => Container(
              decoration: BoxDecoration(
                color: Colors.white,
                border: Border(top: BorderSide(color: Colors.grey[300]!)),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Expanded(
                      child: InkWell(
                    onTap: () {
                      controller.currentIndex.value = 0;
                      controller.pageController.animateToPage(
                        0,
                        duration: _duration,
                        curve: Curves.easeInOut,
                      );
                    },
                    child: _buildNavItem(Icons.home, '首页',
                        controller.currentIndex.value == 0, 0),
                  )),
                  Expanded(
                      child: InkWell(
                    onTap: () {
                      controller.currentIndex.value = 1;
                      controller.pageController.animateToPage(
                        1,
                        duration: _duration,
                        curve: Curves.easeInOut,
                      );
                    },
                    child: _buildNavItem(Icons.medical_services, '问诊',
                        controller.currentIndex.value == 1, 1),
                  )),
                  // Expanded(
                  //     child: InkWell(
                  //   onTap: () {
                  //     controller.currentIndex.value = 2;
                  //     controller.pageController.animateToPage(
                  //       2,
                  //       duration: _duration,
                  //       curve: Curves.easeInOut,
                  //     );
                  //   },
                  //   child: _buildNavItem(Icons.message, '消息',
                  //       controller.currentIndex.value == 2, 2),
                  // )),
                  Expanded(
                      child: InkWell(
                    onTap: () {
                      controller.currentIndex.value = 3;
                      controller.pageController.animateToPage(
                        3,
                        duration: _duration,
                        curve: Curves.easeInOut,
                      );
                    },
                    child: _buildNavItem(Icons.person, '我的',
                        controller.currentIndex.value == 3, 3),
                  ))
                ],
              ),
            )),
      ),
    );
  }

  Widget _buildNavItem(
      IconData icon, String label, bool isSelected, int index) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 8.h),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Icon(
            icon,
            color: isSelected ? Colors.blue[600] : Colors.grey,
          ),
          SizedBox(height: 4.h),
          Text(
            label,
            style: TextStyle(
              fontSize: 12.sp,
              color: isSelected ? Colors.blue[600] : Colors.grey,
            ),
          ),
        ],
      ),
    );
  }
}
